package calculation

import (
	"cloudDevice2/sampleapi/protobuf"
	"cloudDevice2/sampleapi/utils"

	"fmt"
	"log"

	"github.com/golang/protobuf/proto"
)

func PrepareEcgData(pbData []byte) {
	hisNotify := &protobuf.HisNotification{}
	err := proto.Unmarshal(pbData, hisNotify)
	if err != nil {
		log.Println(fmt.Sprintf("parse 80 healh history error:%s", err.Error()))
		return
	}

	switch hisNotify.GetData().(type) {
	case (*protobuf.HisNotification_HisData):
		hisData := hisNotify.GetHisData()
		switch hisNotify.GetType() {
		case protobuf.HisDataType(protobuf.HisDataType_ECG_DATA):
			/*
				save rawDataList with data_time, later combine all ecg data
				with the same data_time, same data_time means it's the same
				ecg measurement
			*/
			ecgData := hisData.GetEcg()
			unix_timestamp := ecgData.GetTimeStamp().GetDateTime().GetSeconds()
			time_str := utils.ParsePbDateTime(int64(unix_timestamp))
			rawDataList := ecgData.GetRawData()
			log.Println(fmt.Sprintf("%s ecg count:%d", time_str, len(rawDataList)))
		}
	}
}
